#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;


  struct ListNode {
      int val;
      ListNode *next;
      ListNode(int x) : val(x), next(NULL) {}
 };

class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val)
    {
        ListNode* cur = head->next;
        ListNode* curprev = head;
        while (cur != NULL)
        {
            if (head->val == val)
            {
                head = head->next;
                break;
            }
            else
            {
                if (cur->val == val)
                {
                    curprev->next = cur->next;
                    break;
                }
                else
                {
                    cur = cur->next;
                    curprev = curprev->next;
                }
            }
        }
        return head;
    }
};